<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>编辑员工信息</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css">
</head>
<body>
<div class="container">
    <div class="sidebar">
        <h2>员工管理系统</h2>
        <div class="user-info">
            <p>欢迎, ${user.username}</p>
            <a href="logout">退出登录</a>
        </div>
        <ul class="menu">
            <li><a href="${pageContext.request.contextPath}/employee?action=list">员工管理</a></li>
            <li><a href="#">部门管理</a></li>
            <li><a href="#">薪资管理</a></li>
            <li><a href="attendance?action=list">考勤管理</a></li>
            <li><a href="#">修改密码</a></li>
            <li><a href="register">注册管理员</a></li>
        </ul>
    </div>

    <div class="main-content">
        <h1>编辑员工信息</h1>

        <c:if test="${not empty error}">
            <div class="error-message">${error}</div>
        </c:if>

        <form action="${pageContext.request.contextPath}/employee" method="post">
            <input type="hidden" name="action" value="update">
            <input type="hidden" name="empId" value="${employee.empId}">

            <div class="form-group">
                <label for="empId">员工ID:</label>
                <input type="text" id="empId" name="empId" value="${employee.empId}" readonly>
            </div>

            <div class="form-group">
                <label for="name">姓名:</label>
                <input type="text" id="name" name="name" value="${employee.name}" required>
            </div>

            <div class="form-group">
                <label for="gender">性别:</label>
                <select id="gender" name="gender" required>
                    <option value="男" ${employee.gender == '男' ? 'selected' : ''}>男</option>
                    <option value="女" ${employee.gender == '女' ? 'selected' : ''}>女</option>
                </select>
            </div>

            <div class="form-group">
                <label for="nation">民族:</label>
                <input type="text" id="nation" name="nation" value="${employee.nation}" required>
            </div>

            <div class="form-group">
                <label for="birthplace">出生地:</label>
                <input type="text" id="birthplace" name="birthplace" value="${employee.birthplace}" required>
            </div>

            <div class="form-group">
                <label for="birthday">出生日期:</label>
                <input type="date" id="birthday" name="birthday" value="${employee.birthday}" required>
            </div>

            <div class="form-group">
                <label for="email">邮箱:</label>
                <input type="email" id="email" name="email" value="${employee.email}" required>
            </div>

            <div class="form-group">
                <label for="phone">电话:</label>
                <input type="text" id="phone" name="phone" value="${employee.phone}" required>
            </div>

            <div class="form-group">
                <label for="address">地址:</label>
                <input type="text" id="address" name="address" value="${employee.address}" required>
            </div>

            <div class="form-group">
                <label for="deptId">部门:</label>
                <select id="deptId" name="deptId" required>
                    <c:forEach items="${departments}" var="dept">
                        <option value="${dept.deptId}"
                            ${employee.deptId == dept.deptId ? 'selected' : ''}>
                                ${dept.deptName} (ID: ${dept.deptId})
                        </option>
                    </c:forEach>
                </select>
            </div>

            <div class="form-group">
                <label for="position">职位:</label>
                <input type="text" id="position" name="position" value="${employee.position}" required>
            </div>

            <div class="form-group">
                <label for="salary">薪资:</label>
                <input type="number" step="0.01" id="salary" name="salary" value="${employee.salary}" required>
            </div>

            <div class="form-group">
                <label for="education">学历:</label>
                <input type="text" id="education" name="education" value="${employee.education}" required>
            </div>

            <div class="form-group">
                <label for="graduateSchool">毕业院校:</label>
                <input type="text" id="graduateSchool" name="graduateSchool" value="${employee.graduateSchool}" required>
            </div>

            <div class="form-group">
                <label for="hireDate">入职日期:</label>
                <input type="date" id="hireDate" name="hireDate" value="${employee.hireDate}" required>
            </div>

            <div class="form-group">
                <label for="status">状态:</label>
                <select id="status" name="status" required>
                    <option value="在职" ${employee.status == '在职' ? 'selected' : ''}>在职</option>
                    <option value="试用" ${employee.status == '试用' ? 'selected' : ''}>试用</option>
                    <option value="离职" ${employee.status == '离职' ? 'selected' : ''}>离职</option>
                </select>
            </div>

            <div class="form-group">
                <label for="contractId">合同ID:</label>
                <input type="text" id="contractId" name="contractId" value="${employee.contractId}" required>
            </div>

            <div class="form-group">
                <label for="regularDate">转正日期:</label>
                <input type="date" id="regularDate" name="regularDate" value="${employee.regularDate}">
            </div>

            <div class="form-group">
                <label for="leaveDate">离职日期:</label>
                <input type="date" id="leaveDate" name="leaveDate" value="${employee.leaveDate}">
            </div>

            <div class="form-actions">
                <button type="submit" class="btn">更新信息</button>
                <a href="${pageContext.request.contextPath}/employee?action=list" class="btn">取消</a>
            </div>
        </form>
    </div>
</div>
</body>
</html>